package test.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import test.domain.Organization;

public interface OrganizationRepository extends JpaRepository<Organization, Integer>, OrganizationRepositoryCustom {
    //empty

    //@Query("SELECT u.organization FROM User u GROUP BY u.organization ORDER BY AVG(u.salary) DESC")
    @Query("SELECT o FROM Organization o JOIN o.users u GROUP BY o ORDER BY AVG(u.salary) DESC")
    List<Organization> findOrganizationsOrderedBySalary();
}
